Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
options(repr.plot.width =15, repr.plot.height =8)
추세를 이용한 분해법 - 가법모형
, 계절주기: s
순환성분()도 있지만 무시한다.
z <-scan("food.txt")t <-1:length(z)food <-ts(z, start=c(1981,1), frequency=12)plot.ts(food, lwd=2, main ="Time Series Plot for food data")
추세와 계절성분이 존재함
데이터에 이분산성이 보임, 즉 시간에 따라 계절 변동의 진폭이 증가하고 있음
가법모형을 사용하기 위해 log 변환 실행
## 이분산성 제거를 위한 변수 변환log_food <-log(food)plot.ts(log_food, lwd=2, main ="Time Series Plot for log(food) data")
진폭이 시간의 흐름에 따라 거의 일정해 진 것을 확인할 수 있음
1. 추세성분 추정: 적합
fit <-lm(log_food ~ t ) summary(fit)
Call:
lm(formula = log_food ~ t)
Residuals:
Min 1Q Median 3Q Max
-0.251154 -0.042190 0.009368 0.051058 0.147910
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.705715 0.012870 287.94 <2e-16 ***
t 0.007216 0.000154 46.86 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.07682 on 142 degrees of freedom
Multiple R-squared: 0.9393, Adjusted R-squared: 0.9388
F-statistic: 2195 on 1 and 142 DF, p-value: < 2.2e-16
One Sample t-test
data: hat_It
t = 5.9991e-16, df = 143, p-value = 1
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.007801616 0.007801616
sample estimates:
mean of x
2.367739e-18
귀무가설을 기각할 수 없다. 즉 평균이 0이다.
hist(hat_It)
dwtest(lm(hat_It~1),alternative ='two.sided')
Durbin-Watson test
data: lm(hat_It ~ 1)
DW = 1.0803, p-value = 2.748e-08
alternative hypothesis: true autocorrelation is not 0
One Sample t-test
data: irregular
t = 0, df = 143, p-value = 1
alternative hypothesis: true mean is not equal to 1
95 percent confidence interval:
0.9923514 1.0076486
sample estimates:
mean of x
1
나눠준거기 떄문에.. 비슷하면 1이랑 가까워지니까 mu=1과 비교하는 것
dwtest(lm(irregular~1), alternative ='two.sided')
Durbin-Watson test
data: lm(irregular ~ 1)
DW = 1.0897, p-value = 3.799e-08
alternative hypothesis: true autocorrelation is not 0